# try:
#     f = open('demo.txt','r',encoding='utf8')  #读取文件的时候可能报错
# except FileNotFoundError as e:              #如果有异常就要重新打开这个文件
#     f =open('demo.txt','w',encoding='utf8')
#     print(e)
# else:
#     content=f.read()  #文件可以正常读取的操作
#     print(content)
# finally:
#     f.close()


try:
    f = open('demo.txt','r',encoding='utf8')  #读取文件的时候可能报错
except Exception as e:              #如果有异常就要重新打开这个文件
    f =open('demo.txt','w',encoding='utf8')
    print(e)
else:
    content=f.read()  #文件可以正常读取的操作
    print(content)
finally:
    f.close()